<?php
if($_REQUEST['Action'] != 'MOD') exit("200");//下单成功
if($_REQUEST['Action'] == 'MOD'){ 
	$return_array = array(
						'orderId'		=>$_REQUEST['Ordern'],
						'personCount'	=>$_REQUEST['Tnum'],
						'USER' 			=> 'admin',
						'PWD'			=> 'admin'
	);
	$response_data = yunding_post($return_array);
	logfile(json_encode($_REQUEST).'|'.$response_data,'yunding_modify_data');
	if($response_data == 1 || $response_data == 3)	exit("200");
	else exit("1077");
} 
else exit("200");

function yunding_post($array){
	// $action = 'http://120.35.41.53:3371/et/ebusiness/newModifyEOrder.do';
	$action = 'http://27.155.96.81:3371/et/ebusiness/newModifyEOrder.do';
	// $post_data= http_build_query($array);
	$o=""; 
	foreach ($array as $k=>$v){ 
		$o.= "$k=".urlencode($v)."&"; 
	} 
	$post_data = substr($o,0,-1); 
	$ch = curl_init(); 
	curl_setopt($ch, CURLOPT_POST, 1); 
	curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);  
	curl_setopt($ch, CURLOPT_URL,$action); 	
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
	curl_setopt($ch, CURLOPT_USERPWD, "admin:admin"); //php调用basic Authorization认证接口
	curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
	$result = curl_exec($ch);
    if (!$result) {  
        return curl_error($ch);  
    }else {  
        return $result;  
 
	}
}

function logfile($word,$path){
	$filepath= '/var/www/html/new/d/logs/api/yunding_check/'.$path.'.txt';
	$word = date("Y-m-d H:i:s")."|".$word;
	if(file_exists($filepath)){
		$maxsize  = 1024*1024*10;
		$filesize = filesize($filepath);
		$filetype = end(explode(".",$filepath));
		$filename = substr($filepath,0,strpos($filepath,'.'));
		if($filesize>$maxsize)
			rename($filepath, $filename.'_'.date('YmdHis').'.'.$filetype);
	}
	$fp = fopen($filepath,"a");
	flock($fp, LOCK_EX);
	fwrite($fp,$word."\n");
	flock($fp, LOCK_UN);
	fclose($fp);
}
?>